package com.borrower.action;

import com.borrower.dto.BorrowInfoBean;
import com.borrower.service.BorrowerServiceImpl;
import com.google.gson.Gson;
import com.pojo.BorrowerBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户注销界面显示用户个人信息
 */
public class UserInfoAction extends Action{
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        PrintWriter out = response.getWriter();
        BorrowerServiceImpl service = new BorrowerServiceImpl();
        HttpSession session = request.getSession();
        String loginName = String.valueOf(session.getAttribute("loginName"));
        List<BorrowerBean> list = service.UserInfoService(loginName);

        for(BorrowerBean b:list){
            if(b.getIsCancel().equals("2")){
                Map<String,String> map = new HashMap<>();
                map.put("isCancel","2");
                map.put("msg","您的账号已注销");
                String str1 = "[{\"msg\":\"您的账号已注销\",\"isCancel\":\"2\"}]";
                out.print(str1);
                session.invalidate();
            }else {
                Gson gson = new Gson();
                String str = gson.toJson(list);
                out.print(str);
            }
        }



    }
}
